#include<bits/stdc++.h>
using namespace std;
inline long long quick_mod(long long b,long long p,long long mod) {
	register long long tmp=b;
    register long long ans=1;
	while(p!=0){
		if(p%2!=0){
			ans=(1ll*ans%mod
                *1ll*tmp%mod)
                %mod;
        }
		tmp=(1ll*tmp%mod
            *1ll*tmp%mod)
            %mod;
		
        p/=2;
	}
	return ans%mod;
}
inline long long read(){
	long long x;
	scanf("%lld",&x);
	return x;
}
long long IN() {
	char ch;
	long long a=0;
	while((ch=getchar())==' '||ch=='\n');
		a+=ch-'0';
	while((ch=getchar())!=' '&&ch!='\n') {
		a*=10;
		a+=ch-'0';
	}
	return a;
}
inline long long check(long long a){
    int ans=1,i=1;
    for(int i=a;i>1;i--){
        if(a%i==0){
            ans++;
            a/=i;
            i=a;
        }
    }
    return ans+1;
}
int main() {
	long long p,e,i,d; //p<=365,e<=365,i<=365,d<=365;
	long long time=1;
	while(time++) {
		//if((p=read())==-1&&(e=read())==-1&&(i=read())==-1&&(d=read())==-1) return 0;
        if((p=IN())+(e=IN())+(i=IN())+(d=IN())==-4) return 0;
        for(int j=0; j<=21252; j++) {
			if(abs(j-p)%23==0&&abs(j-e)%28==0&&abs(j-i)%33==0) {
				cout<<"Case "<<time-1<<": the next triple peak occurs in "<<abs(j-d)<<" days.\n";
				break;
			}
		}
	}
}